infoGo to Tips Page
messageTech Support
  • Prepare for InterviewPrepare for Interview
  • AcknowledgementsAcknowledgements
  • Test hardwareTest hardware
  • What to ExpectWhat to Expect
  • Start InterviewStart Interview
  • Video QuestionVideo Question
  • Video QuestionVideo Question
  • Video QuestionVideo Question
  • Front-end QuestionFront-end Question
  • Workspace QuestionWorkspace Question
  • AvailabilityAvailability
  • Preview & SubmitPreview & Submit
  • Finish InterviewFinish Interview
Powered by

Question 5/5

"Shopping Cart"

Your solution will be scored against a series of unit test cases.


Environment:

This IDE environment gives you access to a Linux based virtual machine.

Your current setup includes the following frameworks installed:

  • Java 11 (test installation via `java -version`)
  • .NET core 3.1.404 (test installation via `dotnet --version`)


Important: You must use a personal machine and network to avoid firewall/proxy issues.


A few tips:

  • `Ctrl + J` to open/close terminal.
  • Click the menu button located at the top left to check out more functionalities/customizations.
  • `apt` and `snap` has been preloaded, so you can use `apt` or `snap` to install packages.
  • Make sure all of your code is written inside this project folder provided to you.
  • You can add new folders or files as per your requirement.


Problem Statement:

In this assessment, you will have to implement an API service for an online shopping cart.

  • To get you started we have provided you with an initial catalog information on a JSON file called “products.json”.
  • If you are unable to connect to backend API, make sure you are not behind any firewall/proxy or using a corporate machine.
  • Different data object have been described below:


Sample product Object:

  • Every product will have properties provided in the sample.
  • Every product has a unique "id"
  • Every product will have a quantity of either 0 or 1.
  • If a product is added to the cart then the quantity in the catalog should be updated to 0.
  • Only products where quantity is greater than 0 (i.e 1) are eligible for purchase.
{
	"id": "1234",
	"name": "product1",
	"price": 200,
    "quantity": 1
}    


Sample Catalog Object:

  • A catalog holds a list of products and is the source of truth about how many products are available.
  • If a product is added to the cart then, the quantity in the product object should be marked at 0.
  • When getting a list of available products, only products with a quantity greater than 0 (i.e equal to 1) should be returned.
{
  "products": [{
  	"id": "001",
  	"name": "chair",
  	"price": 295,
    "quantity": 1      
  }, ...]
}  


Sample Cart Object:

  • For simplicity, there will only be one cart at any time.
  • When an element is added to the cart it becomes unavailable for further purchases.
  • Cart should have the following keys:
  • "products" which will hold a list of products
  • "totalCost" which will hold the sum of prices of all products in the cart.
{
"products": [{
	"id": "001",
	"name": "chair",
	"price": 295
  }],
"totalCost": 295
}



You will have to implement the following API endpoints:


  • Get catalog size
  1. URL: "/catalog/size"
  2. Method: GET
// For Example:
// Request URL: /catalog/size
// Success Response body, statusCode should be 200
{ 
  "success": true,
  "count": 94
}

// Failure Response body, statusCode should be 501, in case products.json file is not found
{ 
  "success": false
}


  • Get Product from catalog by id
  1. URL: "/catalog/:id"
  2. Method: GET
// For example: 
// Request URL: /catalog/001
// Success Response body, statusCode should be 200
{
    "products": [
        {
            "id": "001",
            "name": "chair",
            "price": 295,
            "quantity": 1
        }
    ],
    "success": true
}

// Request URL: /catalog/00000000
// Failure Response body, statusCode should be 404, since product is not found
{ 
  "success": false
}


  • Get shopping cart
  1. URL: "/cart"
  2. Method: GET
// For example: 
// Request URL: /cart
// Success Response body, statusCode should be 200
{
    "products": [
        {
            "id": "001",
            "name": "chair",
            "price": 295,
            "quantity": 1
        }
    ],
    "totalCost": 295 // if products array is empty then totalCost should be 0"success": true
}

// Request URL: /cart
// Failure Response body, statusCode should be 501
{ 
  "success": false
}


  • Get item from shopping cart by id
  1. URL: "/cart/item/:id"
  2. Method: GET
// For example: 
// Request URL: /cart/item/001
// Success Response body, statusCode should be 200
{
    "products": [
        {
            "id": "001",
            "name": "chair",
            "price": 295,
            "quantity": 1
        }
    ],
    "success": true
}

// Request URL: /cart/002
// Failure Response body, statusCode should be 404, since product with 002 is not present in the cart
{ 
  "success": false
}


  • Add item to shopping cart by id
  1. URL: "/cart/item/:id"
  2. Method: POST
// For example: 
// Request URL: /cart/item/001
// Success Response body, statusCode should be 200
{
    "success": true
}

// Request URL: /cart/00000
// Failure Response body, statusCode should be 404, since product is not found
{ 
  "success": false
}

// NOTE: 
// In case if you try to add the same product twice, then it should return 501 with above body
// as product is already added to cart


  • Remove item to shopping cart by id
  1. URL: "/cart/item/:id"
  2. Method: DELETE
// For example: 
// Request URL: /cart/item/001
// Success Response body, statusCode should be 200
{
    "success": true
}

// Request URL: /cart/00000
// Failure Response body, statusCode should be 404, since product is not found
{ 
  "success": false
}

// NOTE: 
// In case if you try to remove the same product twice, then it should return 404 with above body
// as product is already removed from cart


  • Checkout
  1. URL: "/cart/checkout/"
  2. Method: POST
  3. Once checkout is a success, the cart should become empty.
// For example: 
// Request URL: /cart/checkout
// Success Response body, statusCode should be 200
{
  "products": [
        {
            "id": "001",
            "name": "chair",
            "price": 295,
            "quantity": 1
        }
    ],
  "totalCost": 295"success": true
}

  
// Request URL: /cart/checkoout, in case oif cart is empty then it should return following body
// Failure Response body, statusCode should be 501
{ 
  "success": false
}



Note:

  • Your API should be running when you submit your solution, otherwise your solution will not be graded.
  • If you are unable to connect to backend API, make sure you are not behind any firewall/proxy or using a corporate machine.
  • Make sure your code is well documented.
  • Please document all your assumptions.


Note: you can use "apt" or "snap" command to install packages.
34
The screen capture will appear in this box.